package com.hurui.xiaoming.utils;

import android.graphics.Bitmap;
import android.util.Base64;

import java.io.ByteArrayOutputStream;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2017/7/26.
 */

public class TimeUtils {
    public static String getTime(Date date){
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

        return  format.format(date);
    }
    public static String getHktime(String time){
        SimpleDateFormat format = new SimpleDateFormat("MM/dd");
        try {
            Date date = format.parse(time);
            return  format.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static String getFinancetime(String time){
        SimpleDateFormat format = new SimpleDateFormat("MM/dd hh:mm:ss");
        try {
            Date date = format.parse(time);
            return  format.format(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
    public static String Bitmap2StrByBase64(Bitmap bit){
        ByteArrayOutputStream bos=new ByteArrayOutputStream();
        bit.compress(Bitmap.CompressFormat.JPEG, 40, bos);//参数100表示不压缩
        byte[] bytes=bos.toByteArray();
        return Base64.encodeToString(bytes, Base64.DEFAULT);
    }
}
